package com.sumer.psychology.microblog.infrastructure.persistence.mongo;

import com.mongodb.DBObject;
import com.sumer.psychology.common.BusinessException;
import com.sumer.psychology.common.persistence.mongodb.AbstractSimpleMongoRepository;

/**
 * 微博的mongodb资源库
 * <p/>
 * User: zhenguang.zhu
 * Date: 2014/10/9
 * Time: 14:08
 */
public class MongoMicroBlogRepository extends AbstractSimpleMongoRepository {
    private static final String DB_NAME = "sumer_micro_blog";
    private static final String MICRO_KEY = "microBlogId.identity";

    private static final String CHANGE_ERROR = "微博暂不支持修改";

    @Override
    public void add(String data) {
        DBObject microBlog = initializeCreateData(data, key());
        microBlog.put("replies", 0);

        db().getCollection(dbName()).insert(microBlog);
    }

    @Override
    protected String dbName() {
        return DB_NAME;
    }

    @Override
    protected String key() {
        return MICRO_KEY;
    }

    @Override
    public void change(String data) {
        throw new BusinessException(CHANGE_ERROR);
    }
}
